package com.lemon.smartsafety.ui.fragment.safe.data;

import com.ldzs.recyclerlibrary.Mode;
import com.lemon.smartsafety.app.AppManager;
import com.lemon.smartsafety.app.AppService;
import com.lemon.smartsafety.app.BundleKey;
import com.lemon.smartsafety.app.EventTag;
import com.lemon.smartsafety.entity.common.CommonVoEx;
import com.lemon.smartsafety.entity.common.SelectDataI;
import com.lemon.smartsafety.entity.event.datacoll.BuildTypeEvent;
import com.lemon.smartsafety.http.service.SafeDataServices;
import com.lemon.smartsafety.listener.RecyclerTClickListener;
import com.lemon.smartsafety.ui.activity.safe.data.SafeDataCollectionBuildingTypeListActivity;
import com.lemon.smartsafety.ui.adapter.common.SelectAdapter;
import com.lemon.smartsafetynew.ui.fragment.base.BasePullToRefreshFragment;
import com.lemon.smartsafety.utils.common.LoggerHelper;
import com.lemon.smartsafety.utils.common.StringUtils;

import java.util.List;

import kale.adapter.LemonRcvAdapter;

/**
 * Created by Cooliean on 16/3/25.
 * 建筑场所分类
 */
public class SafeDataCollectionBuildingTypeListFragment extends BasePullToRefreshFragment<SelectDataI, List<CommonVoEx>> implements RecyclerTClickListener<SelectDataI> {
    private LoggerHelper loggerHelper = new LoggerHelper(SafeDataCollectionBuildingTypeListFragment.class);

    public static SafeDataCollectionBuildingTypeListFragment newInstance() {
        return new SafeDataCollectionBuildingTypeListFragment();
    }


    private String mOldValue = "";

    @Override
    protected void getBaseArguments() {
        super.getBaseArguments();
        if (getArguments() != null) {
            mOldValue = StringUtils.nullValue(getArguments().getString(BundleKey.OLD_SELECT_VALUE));
        }
    }

    @Override
    protected void initViews() {
        super.initViews();
        pageSize = Integer.MAX_VALUE;//这样设置一下，就不就有加载更多了
        mPullToRefreshRecyclerView.setRefreshMode(Mode.PULL_FROM_START);
    }


    @Override
    public boolean goRefreshOnCreate() {
        return true;
    }

    @Override
    public LemonRcvAdapter<SelectDataI> getLemonAdapter() {
        return new SelectAdapter(mDataList, this, mOldValue);
    }

    @Override
    public String getHttpTag() {
        return EventTag.TAG_SAFE_DATA_COLLECTION_BUILDING_TYPE_LIST;
    }

    @Override
    public void onItemClick(SelectDataI data, int position) {
        BuildTypeEvent event = new BuildTypeEvent();
        event.setTag(SafeDataCollectionBuildingTypeListFragment.class.getName());
        event.setData(data);
        AppService.getBus().post(event);
        AppManager.getAppManager().finishActivity(SafeDataCollectionBuildingTypeListActivity.class);
    }

    @Override
    public void onLoadMore() {

    }

    @Override
    public void onPullRefresh() {
        SafeDataServices.init().getBuildingTypeList();
    }

}
